﻿using System;
using System.IO;
using Common;
using FluentScheduler;
using Model.Sys.Config;
using Model.Sys.Constant;

namespace FScheduler.Job
{
    public class ClearUselessCacheFile:IJob//清除超期24小时未写入的缓存文件
    {
        public void Execute()
        {
            string fileRootPath = Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + CacheConfig.CacheFilePath);
            FileInfo[] files = IOHelper.GetFiles(fileRootPath);

            if (files.Length > 0)
            {
                foreach (var file in files)
                {
                    if (file.Name.StartsWith(Constant.CacheKey.UserInfoLoginCacheKey))
                    {
                        TimeSpan ts = DateTime.Now - file.LastWriteTime;
                        int h = ts.Days * 24 + ts.Hours;
                        if (h >= 24)
                        {
                            File.Delete(file.FullName);
                        }
                    }
                }
            }
            Console.WriteLine("dfadfdsa");
        }
    }
}
